
clear all;
close all;
clc

cd  E:\ReplicateBuild\02_code\03_matlab

store_suffix='baseline';

%%%
% 1 and 2. status quo, and status quo with school propose
%%%
base=['alloc_teach_est_princ_est_restr_',store_suffix,'.mat'];
basefilename=join(base);
folder='../../01_data/05_temp/model/';
savefile=fullfile(folder, basefilename);


basedata=open(savefile);

% 2 is average, 3 is advaantage, 4 is disadvantage
stable_teach_propose=basedata.stable_teach_propose;
status_quo=mean(stable_teach_propose);
status_quo_school=mean(basedata.stable_school_propose);

%%
% 3.  status quo, noisy hiring
%% 

base=['alloc_teach_est_princ_noisy_restr_',store_suffix,'.mat'];
basefilename=join(base);
folder='../../01_data/05_temp/model/';
savefile=fullfile(folder, basefilename);


basedata=open(savefile);

% 2 is average, 3 is advantage, 4 is disadvantage
stable_teach_propose=basedata.stable_teach_propose;
status_quo_noisy=mean(stable_teach_propose);


%%%%%%%%%%%%
%% 4. status quo, plus all options
%%%%%%%%
base=['alloc_teach_est_princ_est_unrestr_',store_suffix,'.mat'];
basefilename=join(base);
folder='../../01_data/05_temp/model/';
savefile=fullfile(folder, basefilename);

basedata=open(savefile);

% 3 is advaantage, 4 is disadvantage
stable_teach_propose=basedata.stable_teach_propose;
all_options=mean(stable_teach_propose);

%%%%%%%%%%%%
%% 5. status quo, and teachers rank by frac dis (princ est, teach fracdis)
%%%%%%%%
base=['alloc_teach_ndis_princ_est_',store_suffix,'.mat'];
basefilename=join(base);
folder='../../01_data/05_temp/model/';
savefile=fullfile(folder, basefilename);

basedata=open(savefile);

% 3 is advantage, 4 is disadvantage
stable_teach_propose=basedata.stable_teach_propose;
teach_fracdis_princ_est=mean(stable_teach_propose);


%%%%%%%%%%%%
%% 6. Status quo and principals rank by VA
%%%%%%%%
base=['alloc_teach_est_princ_va_restr_',store_suffix,'.mat'];
basefilename=join(base);
folder='../../01_data/05_temp/model/';
savefile=fullfile(folder, basefilename);

basedata=open(savefile);

% 3 is advaantage, 4 is disadvantage
stable_teach_propose=basedata.stable_teach_propose;
principal_va=mean(stable_teach_propose);



%%%%%%%%%%%%
%% 7.  Status quo, and previous two changes: principal va, and teach fracdis
%%%%%%%%
base=['alloc_teach_ndis_princ_va_',store_suffix,'.mat'];
basefilename=join(base);
folder='../../01_data/05_temp/model/';
savefile=fullfile(folder, basefilename);

basedata=open(savefile);

% 3 is advantage, 4 is disadvantage
stable_teach_propose=basedata.stable_teach_propose;
teach_fracdis_princ_va=mean(stable_teach_propose);

%%%%%%%%%%%%
%% 7. for first best
%%%%%%%%
base=['alloc_teach_fracdis_princ_va_unrestr_',store_suffix,'.mat'];
basefilename=join(base);
folder='../../01_data/05_temp/model/';
savefile=fullfile(folder, basefilename);

basedata=open(savefile);

% 3 is advaantage, 4 is disadvantage
firstbest_school=basedata.firstbest_school;
first_best=mean(firstbest_school);

 % collect things

% all_options= all_option;
 %principal_va= principal_va;
% teach_va=teach_va;
% teach_va_princ_va=teach_va_princ_va;
% first_best=first_best-status_quo;
display_var= [status_quo all_options principal_va teach_fracdis_princ_est teach_fracdis_princ_va first_best];

%%
% MATLAB script to produce a LaTeX table with dynamic data

% Specify the directory path where you want to save the .tex file
save_path = 'E:\ReplicateBuild\03_output\tables\';

% Complete file path with file name
file_name = [save_path 'allocation_table.tex'];

% Open a file to write
fileID = fopen(file_name,'w');

% Check if the file was opened successfully
if fileID == -1
    error('File could not be opened, check if the path is correct and writable.');
end

% Write the table header and begin the tabular environment
fprintf(fileID, '\\begin{tabular}{lccc}\\hline  \\noalign{\\smallskip} \\multicolumn{1}{l}{Description} &  \\multicolumn{1}{l}{VA disadv.} & \\multicolumn{1}{l}{VA adv.} & \\multicolumn{1}{l}{mean VA}   \\noalign{\\smallskip}  \\\\\\hline\n');
fprintf(fileID, ' \\noalign{\\smallskip} Status quo & %.3f & %.3f & %.3f  \\\\\n', [status_quo(1,4) status_quo(1,3) status_quo(1,2)  ]);
fprintf(fileID, 'Noisy hiring & %.3f & %.3f & %.3f  \\\\\n', [status_quo_noisy(1,4)  status_quo_noisy(1,3)  status_quo_noisy(1,2)    ]);
fprintf(fileID, 'School propose & %.3f & %.3f & %.3f  \\\\\n', [ status_quo_school(1,4) status_quo_school(1,3)  status_quo_school(1,2)  ]);
fprintf(fileID, 'All options (timing) & %.3f & %.3f & %.3f  \\\\\n', [ all_options(1,4) all_options(1,3) all_options(1,2)  ] );
fprintf(fileID, 'Principals rank by VA & %.3f & %.3f & %.3f  \\\\\n', [ principal_va(1,4) principal_va(1,3) principal_va(1,2) ]);
fprintf(fileID, 'Teachers rank by N disadv. & %.3f & %.3f & %.3f  \\\\\n', [ teach_fracdis_princ_est(1,4) teach_fracdis_princ_est(1,3) teach_fracdis_princ_est(1,2)   ]);
fprintf(fileID, 'Previous two changes & %.3f & %.3f & %.3f  \\\\\n', [ teach_fracdis_princ_va(1,4) teach_fracdis_princ_va(1,3)  teach_fracdis_princ_va(1,2)  ]);
fprintf(fileID, 'First best & %.3f & %.3f & %.3f  \\\\\n', [ first_best(1,4) first_best(1,3)  first_best(1,2)    ]);


% End the tabular environment and close the table
fprintf(fileID, ' \\noalign{\\smallskip}\\hline \\end{tabular}\n');

% Close the file
fclose(fileID);

% Notify the user
fprintf('LaTeX table saved to %s\n', file_name);


